<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改广告位</title>
    <link href="../../css/admin/style.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.8.3.min.js" type="text/javascript"></script >
    <script src="../../js/ajaxfileupload.js" type="text/javascript"></script>
    <script>
        $(function (){
            var id = location.search.split("=")[1];
            $("#id").val(id);
            $.get("../../advertising/getadvertisingListById",{id:id},function (res){
                var imgsrc =  "http://127.0.0.1:8080/userImg/advertisingphoto/"+res.data.linkAddress;
                $("#pictureName").val(res.data.pictureName);
                $("#logo").attr("src",imgsrc);
                $("#linkAddress").val(res.data.linkAddress);
            },"json")
        })
        function updateadv(){
            $.post("../../advertising/updateadv",$("#formId").serialize(),function(res){
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                }else {
                    alert(res.msg);
                    location.replace("list.html");
                }
            })
        }

        function fileUpload(){
            $.ajaxFileUpload({
                    url: '../../advertising/fileUpload', //用于文件上传的服务器端请求地址  调用后端接口(interface)
                    fileElementId: 'fileID', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data){
                        console.log(data);
                        if (data.code ==200){
                            var imgsrc = "http://localhost:8080/userImg/advertisingphoto/"+data.data;
                            $("#logo").attr("src",imgsrc);
                            $("#linkAddress").val(data.data);
                        }else if (data.code = 500){
                            console.log(data.msg);
                        }
                    }
                }
            )
        }
    </script>
</head>
<body>
<form id="formId">
    <input type="hidden" id="id" name="id">
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        <ul class="forminfo">
            <li>
                <label>广告名</label>
                <input id="pictureName" name="pictureName" type="text" class="dfinput" />
            </li>
            <li>
                <label>广告图片</label>
                <img id="logo" src='' width='30' height='30'/>
                更换头像<input type="file" name="fileName" accept=".jpg,.png,.gif" id="fileID">
                <input type="button" value="上传" onclick="fileUpload()">
                <input type="hidden" id="linkAddress" name="linkAddress" value="">
            </li>

            <li>
                <input type="button" value="保存" onclick="updateadv()">
            </li>
        </ul>
    </div>
</form>
</body>
</html>